from aria_tests import *

def html_slider_test_code(f, test ):
  valuetext = ""
  valuenow = 50
  valuemin = 0
  valuemax = 100

  # Check for aria-labelledy references
  alabel_list = test['aria-labelledby']
  if len(alabel_list):
    i = 1
    for item in alabel_list:
      f.write("   <div id='alabel_" + str(i) + "'>" + item + "</div>\n")      
      i += 1
 
  f.write("    <div")
  # Add attribute content related to the element
  for attribute in test['attributes']:
    [a, value] = attribute.split('=')
    f.write(" " + a + "='" + value + "'")
  f.write(">\n")
    
  f.write("      <div id='test' role='slider' tabindex='0'\n")
  
  # Check for aria-describedby attribute
  if test['aria-describedby']:
    f.write("      aria-describedby='test_desc'\n")      
  
    
  # Add related ARIA Properties
  for property in test['properties']:
    [p, value] = property.split('=')
    f.write("      " + p + "='" + value + "'\n")
    if p == 'aria-valuemin':
       valuemin = value
    if p == 'aria-valuenow':
       valuenow = value
    if p == 'aria-valuetext':
       valuetext = value
    if p == 'aria-valuemax':
       valuemax = value
    
  # Add related ARIA States
  for state in test['states']:
    [s, value] = state.split('=')
    f.write("      " + s + "='" + value + "'\n")
    
  # Check for title attribute
  if test['title']:
    f.write("      title='" + test['title'] + "'\n")      

  # Check for aria-label attribute
  if test['aria-label']:
    f.write("      aria-label='" + test['aria-label'] + "'\n")      

  # Check for aria-labelledy references
  if len(alabel_list):
    f.write("      aria-labelledby='")
    i = 1    
    for item in alabel_list:
      f.write("alabel_" + str(i) + " " )      
      i += 1
    f.write("'\n")      

  f.write("      >&nbsp;\n")
  
  f.write("      </div>\n")
  f.write("    </div>\n")

  f.write("    <div class='scale'>\n")    
  f.write("      <span class='min'>" + valuemin + "</span>\n")    
  f.write("      <span class='max'>" + valuemax + "</span>\n")
  f.write("    </div>\n")    
  
  if len(valuetext):
    f.write("    <div class='valuenow'>Value = '" + valuetext + "'</div>\n")
  else:
    f.write("    <div class='valuenow'>Value = " + valuenow + "</div>\n")

  # if any aria-describedby content, add it to the page
  if test['aria-describedby']:
    f.write("    <p id='test_desc'>" + test['aria-describedby'] + "</p>\n")



def make_slider_test( group, id, title, path, fname, test):
  print "\nCreating  " + path + fname + "...\n"
  
  fname_test    = "test_" + fname + ".html";
  fname_results = "results_" + fname + ".js";
  
  f = open(path+fname_test,    'w')
  
  if not os.path.isfile(path+fname_results):
    s = open(path+fname_results, 'w')
    make_results_file( s, id, path, fname_test, title, test['description'], 'role', 'slider', test, group )

  path = '../'
  html_head_start(f, path, title)
  html_head_style_link(f, path, 'aria_slider.css', 'all')
  script_add_results_ref( f, fname_results )
  script_reference( f, path, 'aria_menu.js')
  script_set_focus( f, 'test' )
  html_body_start(f, id, title, test)
  html_slider_test_code(f, test)
  html_accessible_name(f, test)
  html_api_mappings(f, test)
  html_body_end(f)
  return fname_results  
  
  
slider_tests = [
  { 'description'      : "Slider with min value of 5 and maximum value of 56 and a current value of 28 and using aria-label for accessible name",    
    'content'          : "",
    'role'             : "slider",
    'attributes'       : ["class=slider"],
    'states'           : [],   
    'properties'       : ["aria-valuemin=5","aria-valuemax=56","aria-valuenow=50",],
    'aria-label'       : "Slider aria-label content",
    'html-label'       : [],
    'aria-labelledby'  : [], 
    'include-node'     : "",    
    'aria-describedby' : "",    
    'title'            : "",
  },
    { 'description'     : "Slider with min value of 5 and maximum value of 56 and a current value of 28 and using aria-labelledy reference for accessible name",    
    'content'          : "",
    'role'             : "slider",
    'attributes'       : ["class=slider"],
    'states'           : [],   
    'properties'       : ["aria-valuemin=5","aria-valuemax=56","aria-valuenow=28",],
    'aria-label'       : "",
    'html-label'       : [],
    'aria-labelledby'  : ["Slider aria-labelledy content",],    
    'include-node'     : "",    
    'aria-describedby' : "",    
    'title'            : "",
  },
  { 'description'      : "Slider using value-text using aria-label for accessible name",    
    'content'          : "",
    'role'             : "slider",
    'attributes'       : ["class=slider"],
    'states'           : [],   
    'properties'       : ["aria-valuemin=0","aria-valuemax=10","aria-valuetext=Half Way",],
    'aria-label'       : "",
    'html-label'       : [],
    'aria-labelledby'  : ["Slider aria-labelledy content",],    
    'include-node'     : "",    
    'aria-describedby' : "",    
    'title'            : "",
  },
  { 'description'      : "Slider using value-text using aria-labelledby reference for accessible name",    
    'content'          : "",
    'role'             : "slider",
    'attributes'       : ["class=slider"],
    'states'           : [],   
    'properties'       : ["aria-valuemin=0","aria-valuemax=10","aria-valuetext=Half Way",],
    'aria-label'       : "Slider aria-label content",
    'html-label'       : [],
    'aria-labelledby'  : [],    
    'include-node'     : "",    
    'aria-describedby' : "",    
    'title'            : "",
  },
  { 'description'      : "Disabled slider with min value of 5 and maximum value of 56 and a current value of 28 and using aria-label for accessible name",    
    'content'          : "",
    'role'             : "slider",
    'attributes'       : ["class=slider disabled"],
    'states'           : ["aria-disabled=true"],   
    'properties'       : ["aria-valuemin=5","aria-valuemax=56","aria-valuenow=50",],
    'aria-label'       : "Slider aria-label content",
    'html-label'       : [],
    'aria-labelledby'  : [],    
    'include-node'     : "",    
    'aria-describedby' : "",    
    'title'            : "",
  },
    { 'description'     : "Slider with min value of 5 and maximum value of 56 and a current value of 28 and using aria-labelledy reference for accessible name",    
    'content'          : "",
    'role'             : "slider",
    'attributes'       : ["class=slider disabled"],
    'states'           : ["aria-disabled=true"],   
    'properties'       : ["aria-valuemin=5","aria-valuemax=56","aria-valuenow=28",],
    'aria-label'       : "",
    'html-label'       : [],
    'aria-labelledby'  : ["Slider aria-labelledy content",],    
    'include-node'     : "",    
    'aria-describedby' : "",    
    'title'            : "",
  },
  { 'description'      : "Slider using value-text using aria-label for accessible name",    
    'content'          : "",
    'role'             : "slider",
    'attributes'       : ["class=slider disabled"],
    'states'           : ["aria-disabled=true"],   
    'properties'       : ["aria-valuemin=0","aria-valuemax=10","aria-valuetext=Half Way",],
    'aria-label'       : "",
    'html-label'       : [],
    'aria-labelledby'  : ["Slider aria-labelledy content",],    
    'include-node'     : "",    
    'aria-describedby' : "",    
    'title'            : "",
  },
  { 'description'      : "Slider using value-text using aria-labelledby reference for accessible name",    
    'content'          : "",
    'role'             : "slider",
    'attributes'       : ["class=slider disabled"],
    'states'           : ["aria-disabled=true"],   
    'properties'       : ["aria-valuemin=0","aria-valuemax=10","aria-valuetext=Half Way",],
    'aria-label'       : "Slider aria-label content",
    'html-label'       : [],
    'aria-labelledby'  : [],    
    'include-node'     : "",    
    'aria-describedby' : "",    
    'title'            : "",
  }
  
]